Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change path max stack allocation to heap #10127

Open
wants to merge 25 commits into
base: master
Choose a base branch
from

Conversation

michal-shalev
Copy link
Contributor

@michal-shalev michal-shalev commented Sep 5, 2024

What?

This PR changes all stack allocations of char arrays sized PATH_MAX to heap allocations.

Why?

Customers with limited stack sizes have recently experienced stack overflow issues when running UCX. Moving these allocations to the heap prevents such overflows.

How?

Heap allocations replace stack allocations for char arrays of size PATH_MAX.

@michal-shalev michal-shalev force-pushed the change-path-max-stack-alloc-to-heap branch from 8cb5ec5 to 2149869 Compare September 5, 2024 11:17
@michal-shalev michal-shalev marked this pull request as draft September 5, 2024 11:31
@michal-shalev michal-shalev added the WIP-DNM Work in progress / Do not review label Sep 5, 2024
@michal-shalev michal-shalev changed the title Change path max stack alloc to heap Change path max stack allocation to heap Sep 5, 2024
@michal-shalev michal-shalev removed the WIP-DNM Work in progress / Do not review label Sep 5, 2024
@michal-shalev michal-shalev marked this pull request as ready for review September 5, 2024 23:27
@michal-shalev michal-shalev force-pushed the change-path-max-stack-alloc-to-heap branch 2 times, most recently from bbc428e to 92fdb9a Compare September 10, 2024 09:03
@michal-shalev michal-shalev marked this pull request as draft September 10, 2024 13:12
@michal-shalev michal-shalev added the WIP-DNM Work in progress / Do not review label Sep 10, 2024
@michal-shalev michal-shalev force-pushed the change-path-max-stack-alloc-to-heap branch from 92fdb9a to 4920c1e Compare September 16, 2024 10:49
@michal-shalev michal-shalev marked this pull request as ready for review September 16, 2024 10:49
@michal-shalev michal-shalev force-pushed the change-path-max-stack-alloc-to-heap branch 3 times, most recently from 0dfae87 to 1bc0050 Compare September 16, 2024 15:59
@michal-shalev michal-shalev force-pushed the change-path-max-stack-alloc-to-heap branch from 1bc0050 to 22cbe36 Compare September 16, 2024 16:43
@michal-shalev michal-shalev force-pushed the change-path-max-stack-alloc-to-heap branch 2 times, most recently from 66bbe34 to 27e63b9 Compare September 16, 2024 17:30
@michal-shalev michal-shalev removed the WIP-DNM Work in progress / Do not review label Sep 17, 2024
Comment on lines 195 to +197
fuse_fd = fuse_open_channel(mountpoint, mountopts);
if (fuse_fd < 0) {
ret = fuse_fd;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fuse_fd = fuse_open_channel(mountpoint, mountopts);
if (fuse_fd < 0) {
ret = fuse_fd;
ret = fuse_open_channel(mountpoint, mountopts);
if (ret< 0) {

}

/* Remove mount point directory */
vfs_log("removing directory '%s'", mountpoint);
ret = rmdir(mountpoint);
if (ret < 0) {
vfs_error("failed to remove directory '%s': %m", mountpoint);
return ret;
goto out_free_mountpoint;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why need goto?

@@ -1778,6 +1795,11 @@ void ucs_config_parse_config_files()

/* Current working dir */
ucs_config_parse_config_file(".", UCX_CONFIG_FILE_NAME, 1);

out_free_path:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused label (pls check other places too)?

@@ -433,10 +433,10 @@ void ucs_memtrack_init()
return;
}

ucs_memtrack_vfs_init();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that change related to this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I changed allocation at VFS to heap and it revealed this issue - an invalid count in the memtrack (tests were failing)


/* Build parent nodes along the rel_path, without associated object */
next_token = rel_path_buf;
token = strsep(&next_token, "/");
while (next_token != NULL) {
current_node = ucs_vfs_node_add_subdir(current_node, token);
if (current_node == NULL) {
return UCS_ERR_NO_MEMORY;
status = UCS_ERR_NO_MEMORY;
goto out_free_abs_path_buf;
}

token = strsep(&next_token, "/");
}

ucs_vfs_node_build_path(current_node, token, abs_path_buf,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ucs_vfs_node_build_path(current_node, token, abs_path_buf,
ucs_vfs_node_build_path(current_node, token, abs_path_buf, PATH_MAX);

ret = mkdir(dirname(sock_path_dir), S_IRWXU);
if ((ret < 0) && (errno != EEXIST)) {
ucs_log(log_level, "failed to create directory '%s': %m",
sock_path_dir);
return -errno;
ret = -errno;
goto out_free_sock_path_dir;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why need goto?

@michal-shalev michal-shalev changed the title Change path max stack allocation to heap BUILD: Change path max stack allocation to heap Sep 18, 2024
@michal-shalev michal-shalev changed the title BUILD: Change path max stack allocation to heap Change path max stack allocation to heap Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants